package xyz.lne.researchgroupmanage.mapper.neo4j;

import org.neo4j.ogm.model.Result;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.stereotype.Repository;
import xyz.lne.researchgroupmanage.entity.neo4j.ResearchGroupNode;

/**
 * Designed By Lne.
 * 2021/3/3 10:26
 */
@Repository
public interface ResearchGroupNodeRepository extends Neo4jRepository<ResearchGroupNode, Long> {
    @Query("MATCH (rg:researchGroup{researchgroupId:$researchgroupId}) RETURN rg")
    ResearchGroupNode findResearchGroupNodeByRGId(Integer researchgroupId);

    @Query("MATCH (p1:researchGroup {researchgroupId: $researchgroupId})-[:krg]->(cuisine1) WITH p1, collect(id(cuisine1)) AS p1Cuisine MATCH (relatedResearchGroup:researchGroup)-[:krg]->(cuisine2) WHERE p1 <> relatedResearchGroup WITH p1, p1Cuisine,relatedResearchGroup, collect(id(cuisine2)) AS relatedResearchGroupCuisine RETURN relatedResearchGroup, gds.alpha.similarity.jaccard(p1Cuisine, relatedResearchGroupCuisine) AS similarity  ORDER BY similarity  DESC  LIMIT $size")
    Result findRelatedResearchGroupByRGId(Integer researchgroupId, Integer size);
}
